package cn.stylefeng.guns.modular.bi.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.bi.entity.vo.DpkcQueryIby;
import cn.stylefeng.guns.modular.bi.model.params.BiCostDiffParam;
import cn.stylefeng.guns.modular.bi.model.result.BiCostDiffResult;
import cn.stylefeng.guns.modular.bi.service.BiCostDiffService;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxStorageStockResult;
import cn.stylefeng.guns.modular.hx.storage.service.HxStorageStockService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.model.result.DictResult;
import cn.stylefeng.guns.sys.modular.system.service.DictService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;


/**
 * 运费成本差异控制器
 *
 * @author zhangzh
 * @Date 2024-05-10 14:24:16
 */
@Controller
@RequestMapping("/dpkcQuery")
public class DpkcQueryController extends BaseController {

    private String PREFIX = "/bi/dpkcQuery";

    @Autowired
    private UserService userService;

    @Autowired
    private DictService dictService;

    @Autowired
    private HxStorageStockService hxStorageStockService;


    @Autowired
    private BasicWarehouseService basicWarehouseService;

    /**
     * 跳转到主页面
     *
     * @author zhangzh
     * @Date 2024-05-10
     */
    @RequestMapping("")
    public String index(Model model) {
        User user = userService.getcurrentUser();
        Long deptId = user.getDeptId();
        Long deliverId = user.getDeliverId();
        //查询可选择仓库
        model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));

        return PREFIX + "/dpkcQuery.html";
    }

    /**
     * 查询列表
     *
     * @author zhangzh
     * @Date 2024-05-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(DpkcQueryIby dpkcQueryIby) {
        User user = userService.getcurrentUser();
        if(ToolUtil.isEmpty(user.getOperateId())){
            dpkcQueryIby.setOperateId(-1L);
        }else{
            dpkcQueryIby.setOperateId(user.getOperateId());

        }
        if(ToolUtil.isEmpty(dpkcQueryIby.getStorageDate())){
            dpkcQueryIby.setStorageDate(DateUtil.getDate());
        }

        dpkcQueryIby.setPositionType("拣货位");

        return this.hxStorageStockService.dpkcQuery(dpkcQueryIby);
    }

    /**
     * 查询列表
     *
     * @author zhangzh
     * @Date 2024-05-10
     */
    @ResponseBody
    @RequestMapping("/listAll")
    public List<HxStorageStockResult> listAll(DpkcQueryIby dpkcQueryIby) {
        User user = userService.getcurrentUser();
        if(ToolUtil.isEmpty(user.getOperateId())){
            dpkcQueryIby.setOperateId(-1L);
        }else{
            dpkcQueryIby.setOperateId(user.getOperateId());

        }
        if(ToolUtil.isEmpty(dpkcQueryIby.getStorageDate())){
            dpkcQueryIby.setStorageDate(DateUtil.getDate());
        }
        dpkcQueryIby.setPositionType("拣货位");
        return this.hxStorageStockService.dpkcQueryAll(dpkcQueryIby);
    }
}


